import React, { Component } from 'react'

export class HelloWorld extends Component {
    // 1.构造方法:
    constructor(){
        console.log(111,"constructor")
        super()
        this.state={
            message:"inzv"
        }
    }

     changeText(params) {
        this.setState({
            message:"你好啊张万森"
        })
    }
  render() {
    console.log(222,"render")
    const {message} = this.state
    return (
      <div>HelloWorld
        <h2>{message}</h2>
        <button onClick={e=>this.changeText()}>修改文本</button>
      </div>
    )
  }
    // 3, 组件被渲染到DOM: 被挂载到DOM
    componentDidMount(){
        console.log(333,"componentDidMount")
      }
       // 4, 组件被更新到DOM:  更新到DOM
    componentDidUpdate(prevProps,prevState,snapshot){
        console.log(444,"componentDidUpdate", prevProps,prevState,snapshot)
      }
       // 5, 组件即将被卸载: 卸载DOM
    componentWillUnmount(){
        console.log(666,"componentWillUnmount")
      }
    //   不常用的生命周期补充
    shouldComponentUpdate(){
        return true
    }
    // 更新之前
    getSnapshotBeforeUpdate(){
        console.log("getSnapshotBeforeUpdate")
        return {
            scrollPosition: 1000
        }
    }
}

export default HelloWorld